package com.lagou.edu.controller;

import com.lagou.edu.intercepter.AuthIntercepter;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 账户管理器
 */
@Controller
@RequestMapping("/account")
public class AccountController {
    public static final String LISTPAGE="/list.jsp";

    @Autowired
    private AccountService accountService;

    @RequestMapping("/login")
    public String login(Account account,
                      HttpServletRequest request,
                      HttpServletResponse response, ModelMap modelMap) throws IOException {
        account = this.accountService.hasAccount(account);
        if (account!=null) {
            request.getSession().setAttribute(AuthIntercepter.USERKEY,account);
            return "redirect:/resume/list";
        }else{
            System.out.println("用户登录失败，跳转登录页面");
            modelMap.addAttribute("errMsg","用户名或密码错误！");
            return AuthIntercepter.LOGINPAGE;
        }
    }



}
